export function parseOption(data,type) {
  var echartsBasicOption = {
    title: {},
    tooltip: {
      trigger: 'axis'
    },
  }
  var chartConfig = data.chartConfig;
  var casted_keys = data.keys;
  var casted_values = data.series;
  var aggregate_data = data.data;
  var newValuesConfig = data.seriesConfig;
  var series_data = [];
  var string_keys = _.map(casted_keys, function(key) {
    return key.join('-');
  });
  var tunningOpt = chartConfig.option;

  var zipDataWithCfg = aggregate_data.map((data,i) => {
    let joined_values = casted_values[i].join('-')
    let s = newValuesConfig[joined_values]
    s.data = data
    delete s.formatter
    delete s.valueAxisIndex
    return s
  })

  for (var j = 0; aggregate_data[0] && j < aggregate_data[0].length; j++) {
    for (var i = 0; i < aggregate_data.length; i++) {
      aggregate_data[i][j] = aggregate_data[i][j] ? Number(aggregate_data[i][j]) : 0;
    }
  }

  for (var i = 0; i < zipDataWithCfg.length; i++) {
    var s = zipDataWithCfg[i];
    s.type = type
    series_data.push(s);
  }

  //
  var xAxis_data = {}
  xAxis_data.type = 'category',
  xAxis_data.data = string_keys

  var echartOption = {
    tooltip: {},
    xAxis: xAxis_data,
    yAxis: {
      type: 'value'
    },
    series: series_data
  };
  return echartOption;
};
